package com.mytrans.transaction;

import java.util.List;
import com.mytrans.util.SpringUtil;

import java.util.HashMap;
import java.util.Map;

public abstract class AbstractContainer implements ExecutorContainer{

    Map<String, TransactionExecutor> executorMap = new HashMap<String, TransactionExecutor>();

    /**
     * 初始化容器，里面是配置的TransationManager的Class信息
     */
    public abstract  <T extends TransactionExecutor> List<Class<T>> tranceConfig();

    public AbstractContainer(){
        init();
    }

    public void init(){
        List<Class<TransactionExecutor>> classList = tranceConfig();
        for(Class<TransactionExecutor> clazz : classList){
            TransactionExecutor transactionExecutor = SpringUtil.getBean(clazz);
            executorMap.put(transactionExecutor.getKey(), transactionExecutor);
        }
    }

    @Override
    public TransactionExecutor getExecutor (String key){
        return executorMap.get(key);
    }

}
